<?php include("../config.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php echo $sitename; ?> - Sysop: Manage Affiliate Data</title>
<meta name="description" content="<?php echo $sitename; ?> - Sysop: Manage Affiliate Data">
<meta name="keywords" content="free to try, software, shareware, freeware, developers, vendors, download, PAD">
<meta name="author" content="Andrey Aleksanyants, M.D.">
<meta name="copyright" content="easy HTools">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" type="text/css" href="../<?php echo $cssfile; ?>">
<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
<table class="tmain" align="center" width="90%" cellspacing="0" cellpadding="0">
<tr>
<td class="tmain">
<table class="tlogo" align="center" width="100%" cellspacing="0" cellpadding="4">
<tr>
<td align="right">
<p><a href="index.php">Home</a></p>
</td>
</tr>
</table>
</td>
</tr><tr>
<td class="tmain">
<br>
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="1">
<tr valign="top">
<td class="tbody">
<h1><?php echo $sitename; ?> - Sysop: Manage Affiliate Data</h1>
<?php

// Requesting form data
$affiliate = $_POST["affiliate"];
$submit    = $_POST["submit"];

if(!$submit) {
	echo "<form name=\"aflmng\" action=\"" . $PHP_SELF . "\" method=\"post\">\n";
	echo "<table class=\"tvisible\" align=\"center\" cellSpacing=\"0\" cellPadding=\"4\">\n";
	echo "<tr>\n";
	echo "<th class=\"tablehead\" colspan=\"2\">Display Affiliate Data</th>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><label for=\"affiliate\"><p><b>Affiliate Service Provider:</b></p></label></td>\n";
	echo "<td><p><select name=\"affiliate\" id=\"affiliate\" size=\"1\">\n";
	echo "<option value=\"All\" selected>Show All</option>\n";
	echo "<option value=\"RegNow\">RegNow only</option>\n";
	echo "<option value=\"Share-It\">Share-It only</option>\n";
	echo "<option value=\"eSellerate\">eSellerate only</option>\n";
	echo "<option value=\"Plimus\">Plimus only</option>\n";
	echo "<option value=\"dis\">Discount URL</option>\n";
	echo "</select></p></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><p><b>Display:</b></p></td>\n";
	echo "<td><input type=\"submit\" class=\"button\" name=\"submit\" value=\"   Display   \"></td>\n";
	echo "</tr>\n</table>\n</form>\n<br>\n";
}
else { // Processing received data
	if(!($link_id = mysql_connect($dbhost, $userid, $userpassword))) {
		die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
	}
	mysql_select_db($dbname);
	
	$numrows = 0;
	if($affiliate == "All") {
		$sql = "SELECT * FROM paddata WHERE affiliate != '' ORDER BY affiliate, company, title";
	}
	if($affiliate == "RegNow") {
		$sql = "SELECT * FROM paddata WHERE affiliate = 'RegNow' ORDER BY affiliate, company, title";
	}
	if($affiliate == "Share-It") {
		$sql = "SELECT * FROM paddata WHERE affiliate = 'Share-It' ORDER BY affiliate, company, title";
	}
	if($affiliate == "eSellerate") {
		$sql = "SELECT * FROM paddata WHERE affiliate = 'eSellerate' ORDER BY affiliate, company, title";
	}
	if($affiliate == "Plimus") {
		$sql = "SELECT * FROM paddata WHERE affiliate = 'Plimus' ORDER BY affiliate, company, title";
	}
	if($affiliate == "dis") {
		$sql = "SELECT * FROM paddata WHERE discounturl <> '' ORDER BY affiliate, company, title";
	}
	$result = mysql_query($sql, $link_id);
	if($result) $numrows = mysql_num_rows($result);
	echo"<p><b>Matching Entries: " . $numrows . "</b></p><br>\n";
	echo "<table class=\"tvisible\" align=\"center\" cellspacing=\"0\" cellpadding=\"4\">\n";
	echo "<tr>\n<td class=\"tablehead\">\n";
	echo "<p><b>No</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Program ID</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Company</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Title</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Affiliate</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Affiliate ID</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Spotlight</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Discount</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Modify</b></p>\n";
	echo "</td>\n<td class=\"tablehead\">\n";
	echo "<p><b>Remove</b></p>\n";
	echo "</td>\n</tr>\n";

	$count = 0;
	for ($i=0; $i<$numrows; $i++) {
		$count++;
		mysql_data_seek($result, $i);
		$query = mysql_fetch_array($result);
		
		$progid       = $query["progid"];
		$company      = htmlspecialchars($query["company"]);
		$website      = htmlspecialchars($query["website"]);
		$title        = htmlspecialchars($query["title"]);
		$homepage     = $query["homepage"];
		$affiliate    = htmlspecialchars($query["affiliate"]);
		$affiliateid  = $query["affiliateid"];
        $spotlight    = $query["spotlight"];
        $discounturl  = $query['discounturl'];
        $discounturl_ex = "no";
        if($discounturl!=""){$discounturl_ex='discount';}
		// Displaying code
		echo "<tr>\n<td>\n";
		echo "<p>" . $count . "</p>\n";
		echo "</td>\n<td>\n";
		echo "<p>" . $progid . "</p>\n";
		echo "</td>\n<td>\n";
		echo "<p><a target=\"_blank\" href=\"" . $website . "\">" . $company . "</a></p>\n";
		echo "</td>\n<td>\n";
		echo "<p><a target=\"_blank\" href=\"" . $homepage . "\">" . $title . "</a></p>\n";
		echo "</td>\n<td>\n";
		echo "<p>" . $affiliate . "</p>\n";
		echo "</td>\n<td>\n";
		echo "<p>" . $affiliateid . "</p>\n";
		echo "</td>\n<td>\n";
		echo "<p>" . $spotlight . "</p>\n";
		echo "</td>\n<td>\n";
		echo "<p>" . $discounturl_ex . "</p>\n";
		echo "</td>\n<td>\n";
		echo "<p><a href=\"aflmodify.php?progid=" . $progid . "&affiliate=" . $affiliate . "&discounturl=".rawurlencode($discounturl)."&affiliateid=" . $affiliateid . "&spotlight=$spotlight\">Modify</a></p>\n";
		echo "</td>\n<td>\n";
		echo "<p><a href=\"aflremove.php?progid=" . $progid . "\">Remove</a></p>\n";
		echo "</td>\n</tr>\n";
	}
	echo "</table><br>\n";

	// Disconnecting from database
	mysql_close($link_id);
}
?>
<br>

</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>